#include "myhead.h"
void YT_cJSON(char *YT)
{
    //要跳过发送过来的头
    char *p=strchr(YT,'{');

    cJSON *obj=cJSON_Parse(p);//把信息存进链表

    //获取对象的键值对,键值对的信息
    cJSON *vall=cJSON_GetObjectItem(obj,"msg");
    printf("是否成功：%s\n",vall->valuestring);
    printf("成功布尔值：%d\n",vall->next->valueint);
    vall=cJSON_GetObjectItem(obj,"code");
    printf("code:%d\n",vall->valueint);


    cJSON *data=cJSON_GetObjectItem(obj,"data");
    vall=cJSON_GetObjectItem(data,"orderNo");
    printf("快递单号：%s\n",vall->valuestring);
    cJSON *info=cJSON_GetObjectItem(data,"info");
    cJSON *num1=cJSON_GetArrayItem(info,0);

    vall=cJSON_GetObjectItem(num1,"theLastTime");
    printf("------------总信息--------------\n");
    printf("最后时间：%s\n",vall->valuestring);
    printf("快递前缀：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("快递单号：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("公司短信：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("手机热线：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("快递公司：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("网址：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("运送时间：%s\n",vall->next->valuestring);
    vall=vall->next;
    printf("状态：%s\n",vall->next->valuestring);
    cJSON *last_num=cJSON_GetObjectItem(num1,"logisticsTraceDetailList");
    printf("------------第一趟--------------\n");
    //继续进入新的数组
    cJSON *a_day=NULL;
    printf("%d\n",cJSON_GetArraySize(last_num));
    for (int i = 0; i < cJSON_GetArraySize(last_num); i++)//在循环要准确获取cJSON编号
    {
        a_day = cJSON_GetArrayItem(last_num, i);
        
        cJSON *areaCode = cJSON_GetObjectItem(a_day, "areaCode");
        cJSON *areaName = cJSON_GetObjectItem(a_day, "areaName");
        cJSON *subLogisticsStatus = cJSON_GetObjectItem(a_day, "subLogisticsStatus");
        cJSON *time = cJSON_GetObjectItem(a_day, "time");
        cJSON *logisticsStatus = cJSON_GetObjectItem(a_day, "logisticsStatus");
        cJSON *desc = cJSON_GetObjectItem(a_day, "desc");

        printf("快递短号：%s\n", areaCode ? areaCode->valuestring : "N/A");
        printf("地址：%s\n", areaName ? areaName->valuestring : "N/A");
        printf("接受：%s\n", subLogisticsStatus ? subLogisticsStatus->valuestring : "N/A");
        printf("时间：%ld\n", time ? time->valueint : 0);
        printf("物流状态：%s\n", logisticsStatus ? logisticsStatus->valuestring : "N/A");
        printf("物流信息：%s\n", desc ? desc->valuestring : "N/A");
        printf("跑的第%d次\n", i);
    }
    vall=cJSON_GetObjectItem(num1,"logisticsStatus");
    printf("最后状态：%s\n",vall->valuestring);

    cJSON_Delete(obj);//只释放跟对象
}